<template>
	<view>
		<view class="background-color_FFFFFF">



			<view class="">
				<view class="display-a margin-bottom_20rpx padding-top_30rpx">
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.finish_number?countObj.finish_number:0}}</view>
						<view class="color_333333">已发布数量</view>
					</view>
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.wait_count?countObj.wait_count:0}}</view>
						<view class="color_333333">待发布数量</view>
					</view>
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.failed_number?countObj.failed_number:0}}</view>
						<view class="color_333333">发布失败</view>
					</view>
				</view>

				<view class="display-a padding-bottom_30rpx p-bo">
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.total_play?countObj.total_play:0}}</view>
						<view class="color_333333">曝光量</view>
					</view>
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.total_like?countObj.total_like:0}}</view>
						<view class="color_333333">点赞量</view>
					</view>
					<view class="label-data">
						<view class="color_1E6CEB">{{countObj.total_comment?countObj.total_comment:0}}</view>
						<view class="color_333333">评论量</view>
					</view>
				</view>
			</view>

			<view class="tabs-2 margin-bottom_20rpx">
				<scroll-view id="tab-bar" class="scroll-h" :scroll-x="true" :show-scrollbar="false">
					<view v-for="(item,index) in statusList" :key="index" class="uni-tab-item" @click="selTab(item.id)">
						<view :class="taskStatus == item.id ? 'uni-tab-item-title-active' : 'uni-tab-item-title'">
							{{item.name}}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>

		<mescroll-body ref="mescrollRef" :height="windowHeight+'rpx'" @init="mescrollInit" @down="downCallback"
			@up="upCallback" :up="upOption" :down="downOption">
			<block v-for="(item,index) in list" :key="index">
				<view class="list-public" style="padding: 0;">
					<view class="display padding-bottom_20rpx p-bo">
						<image v-if="item.avatar" class="avater" :src="item.avatar"></image>
						<image v-else class="avater" :src="severAvatar"></image>
						<view class="list-name">
							<view class="font-size_30rpx margin-bottom_10rpx">{{item.nickname}}</view>
							<view class="color_999999 font-size_26rpx">(待)发布时间：{{item.execute_date}}</view>
						</view>
						<view v-if="item.is_status == 1" class="list-label">待发布</view>
						<view v-if="item.is_status == 2 " class="list-label"
							style="background: #1E6CEB;">已发布</view>
						<view v-if="item.is_status == 3 " class="list-label"
							style="background: #FF0000;">发布失败</view>
					</view>
					<block >
						<view :class="selLabel == 5 ? 'display-a padding_20rpx_0' : 'display-a padding_20rpx_0 p-bo'">
							<view class="list-data">
								<view class="color_333333 font-size_30rpx margin-bottom_10rpx">
									{{item.total_play?item.total_play:0}}
								</view>
								<view class="color_888">曝光量</view>
							</view>
							<view class="list-data-line"></view>
							<view class="list-data">
								<view class="color_333333 font-size_30rpx margin-bottom_10rpx">
									{{item.total_like?item.total_like:0}}
								</view>
								<view class="color_888">点赞数</view>
							</view>
							<view class="list-data-line"></view>
							<view class="list-data">
								<view class="color_333333 font-size_30rpx margin-bottom_10rpx">
									{{item.total_comment?item.total_comment:0}}
								</view>
								<view class="color_888">评论数</view>
							</view>
						</view>
						

						<view class="display-a padding_30rpx_0" v-if="selLabel == 1 || selLabel == 3 ">
							<view class="comment" @click="getComment(item.id)">查看评论
							</view>
							<view class="list-data-line"></view>
							<view class="comment" @click="getVideo(item.forward_video)">查看作品</view>
							<view class="list-data-line" v-if="selLabel == 6"></view>
							<view v-if="selLabel == 6" class="comment" @click="getBatch(item)">添加评论</view>
						</view>
						<view class="display-a-jc padding_30rpx_0" v-if="selLabel == 2 || selLabel == 4">
							<view class="comment" style="width: 710rpx;" @click="getVideo(item.forward_video)">查看作品</view>
						</view>
					</block>
					
					<!-- <block v-if="item.taskStatus == 3 || item.publishStatus == 3">
						<view class="padding_30rpx p-bo">失败原因: <span
								class="color_FF0000 margin-left_10rpx">{{item.hint}}</span></view>
						<view class="display-a-jc padding_30rpx_0" v-if="selLabel != 1 ">
							<view class="comment" style="width: 710rpx;"
								@click="reissue(item.id,item.taskStatus,item.publishStatus,item.cookie)">立即补发</view>
						</view>
					</block> -->
				</view>
			</block>
		</mescroll-body>

		<!-- <image class="matrix-8" @click="getUserVideoData()" :src="matrix8"></image> -->

		<sunui-popup ref="pop2">
			<template v-slot:content>
				<view class="display-a-js padding_30rpx">
					<view></view>
					<view class="color_FF0000" @click="closeBatch()">关闭</view>
				</view>
				<view style="padding: 34rpx;">
					<view class="font-size_32rpx font-weight_bold margin-bottom_30rpx">评论内容</view>
					<input type="text" class="input-name" maxlength="400" placeholder="请输入评论内容"
						placeholder-class="placeholder" v-model="replyContent" />
					<view class="list-but" @click="getReply()">确认评论</view>
				</view>
			</template>
		</sunui-popup>

	</view>
</template>

<script>
	import FormData from '../../utils/formData.js';
	import axios from 'axios';
	import {
		post
	} from '../../utils/http.js';
	export default {
		data() {
			const oldList = [{
				name: '发布成功',
				num: 0,
				isShow: true
			}, {
				name: '待发布',
				num: 0,
				isShow: true
			}, {
				name: '发布失败',
				num: 0,
				isShow: true
			}, {
				name: '曝光总量',
				num: 0,
				isShow: true
			}, {
				name: '点赞总数',
				num: 0,
				isShow: true
			}, {
				name: '评论总数',
				num: 0,
				isShow: true
			}, {
				name: '弹幕总数',
				num: 0,
				isShow: false
			}, {
				name: '投币总数',
				num: 0,
				isShow: false
			}, {
				name: '分享总数',
				num: 0,
				isShow: false
			}, {
				name: '收藏总数',
				num: 0,
				isShow: false
			}, ];

			return {
				severAvatar:this.$imgs.severAvatar,
				oldList,
				listStatic: [...oldList],
				// matrix8: this.$img.matrix8,
				// 下拉配置项
				downOption: {
					auto: false
				},
				// 上拉配置项
				upOption: {
					auto: false
				},

				list: [],

				statusList: [],
				taskStatus: '',


				windowHeight: '',

				name: '',

				countObj: {}, //数据统计

				selLabel: '', //1抖音h5发布 3矩阵首页待用户发布查询 4矩阵首页快手发布 5.B站发布
				task_id: '', //任务ID

				ms: 1000 * 60,
				lastClick: Date.now() - (1000 * 60),
				listObj: {},
				replyContent: '',
				isWhether: true, //判断重复点击
			}
		},

		onLoad(options) {
			console.log(options)
			//获取系统信息
			uni.getSystemInfo({
				success: res => {
					if (options.selLabel == 5) {
						this.windowHeight = res.windowHeight * 2 - 610;
					} else {
						this.windowHeight = res.windowHeight * 2 - 384;
					}
				}
			})
			if (options.taskId && options.selLabel) {
				this.task_id = options.taskId;
				this.selLabel = options.selLabel;
				this.statusList = [{
						id: '',
						name: '全部'
					},
					{
						id: '1',
						name: '待发布'
					},
					{
						id: '2',
						name: '发布成功'
					},
					{
						id: '3',
						name: '发布失败'
					}
				];
				this.getCount();
				// if (this.selLabel == 6 || this.selLabel == 3 || this.selLabel == 1) {
				// 	this.allGetNum()
				// }
				this.$nextTick(() => {
					this.mescroll.resetUpScroll();
				});
			}
		},

		onShow() {

		},

		methods: {
			closeBatch() {
				this.$refs.pop2.close();
			},
			getBatch(obj) {
				this.listObj = obj;
				this.$refs.pop2.show({
					style: 'background-color:#fff;width:750rpx;height:auto;border-radius: 40rpx 40rpx 0 0;',
					anim: 'bottom',
					position: 'bottom',
					shadeClose: false,
				});
			},
			async getReply() {
				console.log('。。。')
				if (!this.replyContent) {
					this.$sun.toast("请输入回复内容", 'none');
					return;
				}

				let formdata = new FormData();
				formdata.append('cookie', this.listObj.cookie);
				formdata.append('note_id', this.listObj.noteId);
				formdata.append('content', this.replyContent);
				let data = formdata.getData();
				if (!this.isWhether) {
					return;
				}
				this.isWhether = false;

				// this.listObj.content = this.replyContent;
				wx.request({
					url: this.$api.xhsauthorizeComment,
					method: 'POST',
					header: {
						'content-type': data.contentType
					},
					data: data.buffer,
					success: async (result) => {

						console.log(result)
						if (result.data.code == 200) {
							this.$sun.toast(result.data.data.data.toast, 'none');
							setTimeout(() => {
								this.replyContent = '';
								this.$refs.pop2.close();
								this.isWhether = true;
								this.$nextTick(() => {
									this.mescroll.resetUpScroll();
								});
							}, 2000);
						} else {
							this.isWhether = true;
							this.$sun.toast('发布失败', 'none');
						}




					}
				});

			},

			async allGetNum() {
				this.listStatic[0].num = 0
				this.listStatic[1].num = 0
				this.listStatic[2].num = 0
				this.listStatic[3].num = 0
				this.listStatic[4].num = 0
				this.listStatic[5].num = 0

				this.listStatic[6].num = 0
				this.listStatic[7].num = 0
				this.listStatic[8].num = 0
				this.listStatic[9].num = 0
				// this.list=this.oldList  // 重置总数据
				// if (this.selLabel == 5) {
				// 	this.accountLists.blblPublishId = this.accountLists.dyPublishId; // 创建一个新的属性
				// 	// delete this.accountLists.dyPublishId; // 删除原始的属性
				// }
				// const detailsApi = this.publish.types == 5 ? bilGetQueryStatistics : this.publish.types == 4 ?
				// 	getKsEventDetailsCount : getEventDetailsList;
				// url: this.selLabel == 4 ? this.$api.getKsEventDetailsCount : this.selLabel == 5 ? this.$api
				// 	.bilGetQueryStatistics : this.$api.getEventDetailsCount,


				const result = await this.$http.post({
					url: this.selLabel == 4 ? this.$api.getKsEventDetailsCount : this.selLabel == 5 ? this.$api
						.bilGetQueryStatistics : this.selLabel == 6 ? this.$api.getEventDetailsListXhs : this
						.$api.getEventDetailsListDy,
					data: {
						dyPublishId: this.task_id,
						blblPublishId: this.task_id,
						types: this.selLabel,


					}
				});
				if (result.code == 2000) {
					// this.countObj = result.data;

					console.log('查询“查看进度”list总数data', result.data)
					if (this.selLabel == 5) {
						const res = await this.$http.post({
							url: this.$api.getEventDetailsListDy,
							data: {
								dyPublishId: this.task_id,
								blblPublishId: this.task_id,
								types: this.selLabel
							}
						});
						if (res.code == 2000) {
							console.log("allData", res.data)
							let list = res.data.length > 0 ? res.data : []

							/*`task_status：'发布状态0未发布1发布中2发布完成3发布错误'*/
							let daiRelease = 0 //待发布(总)
							let successRelease = 0 //发布成功(总)
							let failRelease = 0 //发布失败(总)
							for (let i = 0; i < list.length; i++) {
								console.log('list[i]', list[i])
								if (list[i].taskStatus == 0) {
									daiRelease++ //待发布
								}
								if (list[i].taskStatus == 2) {
									successRelease++ //发布成功
								}
								if (list[i].taskStatus == 3) {
									failRelease++ //发布失败
								}
							}
							this.listStatic[0].num = successRelease
							this.listStatic[1].num = daiRelease
							this.listStatic[2].num = failRelease




							this.statisticsInfo = result.data

							this.listStatic[3].num = data.playCount //曝光总量
							this.listStatic[4].num = data.diggCount //点赞总数
							this.listStatic[5].num = data.commentCount //评论总数

							this.listStatic[6].isShow = true
							this.listStatic[6].num = data.danmaku //弹幕总数

							this.listStatic[7].isShow = true
							this.listStatic[7].num = data.coin //投币总数

							this.listStatic[8].isShow = true
							this.listStatic[8].num = data.share //分享总数

							this.listStatic[9].isShow = true
							this.listStatic[9].num = data.favorite //收藏总数
							return
						}

					}
					let list = result.data.length > 0 ? result.data : []
					/*`task_status：'发布状态0未发布1发布中2发布完成3发布错误'*/
					let daiRelease = 0 //待发布(总)
					let successRelease = 0 //发布成功(总)
					let failRelease = 0 //发布失败(总)
					let playAll = 0 //曝光数(总)
					let diggAll = 0 //点赞数(总)
					let commentAll = 0 //评论数(总)

					for (let i = 0; i < list.length; i++) {
						console.log('list[i]', list[i])
						// publish.types ： 1_h5  2_cookie 3_代员工发布到抖音 4_快手
						// publishStatus 快手发布状态（1.已执行（成功） 2.未执行（待发布）', 没有失败状态
						console.log("this.publish.types", this.selLabel)
						if (this.selLabel == 4) {
							if (list[i].publishStatus == 2) {
								daiRelease++ //待发布
							}
							if (list[i].publishStatus == 1) {
								successRelease++ //发布成功
							}
						} else {

							if (list[i].taskStatus == 0) {
								daiRelease++ //待发布
							}
							if (list[i].taskStatus == 2) {
								successRelease++ //发布成功
							}
							if (list[i].taskStatus == 3) {
								failRelease++ //发布失败
							}
						}
						if (list[i] && list[i].taskStatus != 0) {
							console.log("list[i].doyiDate.list[0].statistics.digg_count", list[i])
							let exposureAmount = list[i].exposureAmount ? list[i].exposureAmount : 0
							let upvoteAmount = list[i].upvoteAmount ? list[i].upvoteAmount : 0
							let commentAmount = list[i].commentAmount ? list[i].commentAmount : 0
							playAll += exposureAmount //曝光数
							diggAll += upvoteAmount //点赞数
							commentAll += commentAmount //评论数
						}
					}
					console.log("daiRelease,successRelease", daiRelease, successRelease)

					console.log('successRelease', successRelease)

					// daiRelease: 待发布(总)
					// successRelease: 发布成功(总)
					// failRelease: 发布失败(总)
					// playAll: 曝光数(总)
					// diggAll: 点赞数(总)
					// commentAll: 评论数(总)
					this.listStatic[0].num = successRelease
					this.listStatic[1].num = daiRelease
					this.listStatic[2].num = failRelease
					this.listStatic[3].num = playAll
					this.listStatic[4].num = diggAll
					this.listStatic[5].num = commentAll
					console.log("this.list======", this.listStatic)



				}


			},

			//统计数据
			async getCount() {
				const result = await this.$http.get({
					url: this.$api.videoStatis,
					data: {
						uid: uni.getStorageSync("uid"), 
						task_id: this.task_id
					}
				});
				if (result.errno == 0) {
					this.countObj = result.data;
				} else {
					this.$sun.toast(result.messga, 'none')
				}
			},

			//立即发布
			async reissue(id, taskStatus, publishStatus, cookie) {
				let result = null;
				if (this.selLabel == 1 || this.selLabel == 3) {
					let formdata = new FormData();
					formdata.append('cookie', cookie);

					let data = formdata.getData();
					console.log(data)

					wx.request({
						url: this.$api.creator_info,
						method: 'POST',
						header: {
							'content-type': data.contentType
						},
						data: data.buffer,
						success: async (res) => {

							console.log(res)
							if (res.data.code == 200 && res.data.data.status_code == 8) {
								this.$sun.toast('当前用户未登录请重新授权', 'none')
							} else {
								if (taskStatus == 0 || taskStatus == 3) {
									result = await this.$http.post({
										url: this.selLabel == 5 ? this.$api.bilReissueTimedTasks :
											this.$api.immediateDy,
										data: {
											id: id
										}
									});
								}
								if (publishStatus == 2 || publishStatus == 3) {
									result = await this.$http.get({
										url: this.$api.immediateKs,
										data: {
											id: id,
											publishStatus: publishStatus
										}
									});
								}

								if (result.code == 2000) {
									this.$sun.toast(result.msg);
									setTimeout(() => {
										this.$nextTick(() => {
											this.mescroll.resetUpScroll();
										});
									}, 2000);
								} else {
									this.$sun.toast(result.msg, 'none');
								}
							}

						}
					});


				} else {
					if (taskStatus == 0 || taskStatus == 3) {
						if (this.selLabel != 6) {
							result = await this.$http.post({
								url: this.selLabel == 5 ? this.$api.bilReissueTimedTasks : this.selLabel == 6 ?
									this.$api.xhsPublishNow : this.$api.immediateDy,
								data: {
									id: this.selLabel != 6 ? id : undefined,
									accountId: this.selLabel == 6 ? id : undefined
								}
							});
						} else {
							result = await this.$http.get({
								url: this.$api.xhsPublishNow,
								data: {

									accountId: this.selLabel == 6 ? id : undefined
								}
							});
						}


					}
					if (publishStatus == 2 || publishStatus == 3) {
						result = await this.$http.get({
							url: this.$api.immediateKs,
							data: {
								id: id,
								publishStatus: publishStatus
							}
						});
					}

					if (result.code == 2000) {
						this.$sun.toast(result.msg);
						setTimeout(() => {

							if (this.selLabel == 6 || this.selLabel == 3 || this.selLabel == 1) {
								this.allGetNum()
							} else {
								this.getCount();
							}
							this.$nextTick(() => {
								this.mescroll.resetUpScroll();
							});
						}, 2000);
					} else {
						this.$sun.toast(result.msg, 'none');
					}
				}

			},

			/*  手动刷新  */
			async getUserVideoData() {

				if (Date.now() - this.lastClick >= this.ms) {
					this.lastClick = Date.now();
				} else {
					this.$sun.toast("请勿频繁操作,一分钟后在刷新!", 'none');
					return;
				}

				let getUrl = '';
				let getData = null;

				if (this.selLabel == 5) {
					getUrl = this.$api.bilGetDataRefresh;
					getData = {
						types: 5,
						username: uni.getStorageSync("staffCode"),
						blblPublishId: this.task_id
					}
				}

				if (this.selLabel == 1 || this.selLabel == 3 || this.selLabel == 4) {
					getUrl = this.$api.dataRefreshDy;
					getData = {
						dyPublishId: this.task_id,
						merchantId: uni.getStorageSync("merchantId"),
						type: this.selLabel
					}
				}

				const result = await this.$http.post({
					url: getUrl,
					data: getData
				});
				if (result.code == 2000) {
					this.$nextTick(() => {
						this.mescroll.resetUpScroll();
					});
				} else {
					this.$sun.toast("因有异常数据,刷新失败", 'none');
				}

			},

			//查看评论

			getComment(id) {
				uni.navigateTo({
					url: '/pages/matrix/comment?id='+id+'&tabId='+this.selLabel
				})
			},

			//查看作品
			getVideo(url) {
				console.log(url)
				if(url){
					uni.navigateTo({
						url: '/pages/matrix/video?url=' + url
					})
				}else{
					this.$sun.toast('当前没有作品','none')
				}
				
				
			},

			selTab(type) {
				this.taskStatus = type;
				this.$nextTick(() => {
					this.mescroll.resetUpScroll();
				});
			},

			// 输入事件
			inputChange(e) {
				this.name = e.detail.value;
				// this.$nextTick(() => {
				// 	this.mescroll.resetUpScroll();
				// });

			},
			confirmChange(e) {
				this.name = e.detail.value;
				// this.$nextTick(() => {
				// 	this.mescroll.resetUpScroll();
				// });
			},

			async upCallback(scroll) {
				const result = await this.$http.post({
					url: this.$api.videoList,
					data: {
						uid: uni.getStorageSync("uid"),


						task_id: this.task_id,

						is_status: this.taskStatus,

						// day: this.yeartime + '-' + this.monthtime + '-' + this.dayTime,


						page: scroll.num,
						limit: 10
					}
				});
				if (result.errno == 0) {
					this.getCount();

					this.mescroll.endByPage(result.data.list.length, result.data.total);
					if (scroll.num == 1) this.list = [];
					this.list = this.list.concat(result.data.list);
				}
			},

		}
	}
</script>

<style lang="scss">
	.input-name {
		width: 640rpx;
		border: 2rpx solid #EBEBEB;
		border-radius: 10rpx;
		padding: 30rpx 20rpx;
		margin-bottom: 40rpx;
	}
	.img-head {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		margin-left: 112rpx;
		margin-top: 18rpx;
	}

	.reply-content {
		width: 550rpx;
		background-color: #F1F1F1;
		color: #666;
		border-radius: 10rpx;
		padding: 10rpx 20rpx;
	}

	.list-but {
		width: 600rpx;
		background-color: #0E8FF3;
		padding: 24rpx;
		font-size: 30rpx;
		font-weight: bold;
		text-align: center;
		color: #FFFFFF;
		margin-left: 42rpx;

	}

	.matrix-8 {
		width: 96rpx;
		height: 96rpx;
		position: fixed;
		right: 14rpx;
		bottom: 180rpx;
		z-index: 99;
	}

	.color_888 {
		font-size: 26rpx;
		color: #888;
	}

	.comment {
		width: 352rpx;
		text-align: center;
		color: #1E6CEB;
	}

	.list-data-line {
		background-color: #ECECEC;
		height: 30rpx;
		width: 4rpx;
	}

	.list-data {
		width: 234rpx;
		text-align: center;
	}

	.list-label {
		display: inline-block;
		padding: 0 14rpx;
		border-radius: 0 10rpx;
		color: #FFFFFF;
		font-size: 26rpx;
		margin-left: auto;
		background-color: #A1A1A1;
		height: 46rpx;
		line-height: 46rpx;
	}

	.list-name {
		width: 420rpx;
		margin-top: 26rpx;
	}

	.avater {
		width: 84rpx;
		height: 84rpx;
		border-radius: 50%;
		margin: 26rpx 20rpx 0;
	}

	.color_1E6CEB {
		color: #1E6CEB;
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 8rpx;
	}

	.label-data {
		text-align: center;
		width: 250rpx;
	}

	.search-x {
		width: 710rpx;
		margin: 0 20rpx 10rpx;
		background-color: #F7F7F7;
		border-radius: 100rpx;
		padding: 20rpx;
	}

	.tabs-2 {
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		/* #ifdef MP-ALIPAY || MP-BAIDU */
		height: 100vh;
		/* #endif */
	}

	.scroll-h {
		width: 750rpx;
		// padding: 20rpx 0;
		background-color: #FFFFFF;
		margin-bottom: 20rpx;
		flex-direction: row;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	.uni-tab-item {
		/* #ifndef APP-PLUS */
		display: inline-block;
		/* #endif */
		flex-wrap: nowrap;
	}

	.uni-tab-item-title {
		margin: 0 50rpx;
		padding: 30rpx 0 20rpx;
		flex-wrap: nowrap;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	.uni-tab-item-title-active {
		margin: 0 50rpx;
		padding: 30rpx 0 20rpx;
		color: #1C6EFF;
		border-bottom: 4rpx solid #1C6EFF;
	}
</style>